/**
 * Created by yuris on 10.02.15.
 */
package model {
import model.objects.*;

import messages.ModelToControllerMessage;


import mvcexpress.mvc.Proxy;



public class WarehouseDataProxy extends Proxy{
    private var _warehouseDataShort:Object = null;

    private var _volume:uint = 0;
    private var _currentTime:uint = 0;
    private var _products:Vector.<ProductWarehouseData> = new <ProductWarehouseData>[];
    //private var _updateSignal:UpdateDataSignal = new UpdateDataSignal();

    public static const MESSAGE_UPDATE_WAREHOUSE:String = "MESSAGE_UPDATE_WAREHOUSE";

    public static const COMMAND_UPDATE_PRODUCT:String = "COMMAND_UPDATE_PRODUCT";
    public static const COMMAND_ADD_CELL:String = "COMMAND_ADD_CELL";
    //public static const UPDATE_PRODUCT_DELIVER_TIME_REST_SIGNAL:String = "UPDATE_PRODUCT_DELIVER_TIME_REST_SIGNAL";

    public function WarehouseDataProxy() {

    }
    public function get shortData():Object {
        return _warehouseDataShort;
    }
    public function set shortData(value:Object):void {
        this._warehouseDataShort = value;
        sendMessage(ModelToControllerMessage.USER_WAREHOUSE_DATA_INPUT, this._warehouseDataShort);
    }

    public function get size():uint {
        return _products.length;
    }

    public function get volume():uint {
        return _volume;
        //TODO: Send volume-change message
    }

    public function getProductData(cellNum:int):ProductWarehouseData
    {
        return this._products[cellNum];
    }
    private var _bufProduct:ProductWarehouseData;
    public function updateCellData(cellNum:int, product:ProductWarehouseData):void{
        this._bufProduct = this._products[cellNum];
        this._products[cellNum] = product;
        this._sendUpdate(COMMAND_UPDATE_PRODUCT,{cellNum:cellNum, product:product, product_old:this._bufProduct});
    }

    private function _sendUpdate(command:String, param:Object):void {
        this.sendMessage(MESSAGE_UPDATE_WAREHOUSE, {command:command, param:param});
    }

    public function addCell():void {
        this._products.push(null);
        this._sendUpdate(COMMAND_ADD_CELL, {newSize:size});
    }

    public function set currentTime(value:uint):void {
        _currentTime = value;
        //TODO: Send time-update message
    }

    public function set volume(value:uint):void {
        _volume = value;
    }
}
}
